package sounds;

import java.io.File;
import java.io.FileInputStream;
import javax.sound.sampled.*;

public class Sound {
       
    
    Runnable rumoreTada = new Runnable() {
        public void run() {
            try {
                File rumore = new File("src/sounds/tada.wav");
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new FileInputStream(rumore));
                AudioFormat audioFormat = audioInputStream.getFormat();
                DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioFormat);
                Clip clip = (Clip) AudioSystem.getLine(dataLineInfo);
                clip.open(audioInputStream);
                clip.start();
            } catch (Exception e) {  e.printStackTrace();  }
        }
    };

    Runnable rumoreBop = new Runnable() {
        public void run() {
            try {
                File rumore = new File("src/sounds/pop.wav");
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new FileInputStream(rumore));
                AudioFormat audioFormat = audioInputStream.getFormat();
                DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioFormat);
                Clip clip = (Clip) AudioSystem.getLine(dataLineInfo);
                clip.open(audioInputStream);
                clip.start();
            }
            catch (UnsupportedAudioFileException e1) { e1.printStackTrace();}
            catch (Exception e) {  e.printStackTrace();  }
        }
    };


    Runnable rumoreLoser = new Runnable() {
        public void run() {
            try {
                File rumore = new File("src/sounds/loser.wav");
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new FileInputStream(rumore));
                AudioFormat audioFormat = audioInputStream.getFormat();
                DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioFormat);
                Clip clip = (Clip) AudioSystem.getLine(dataLineInfo);
                clip.open(audioInputStream);
                clip.start();
            }
            catch (UnsupportedAudioFileException e2) { e2.printStackTrace();}
            catch (Exception e) {  e.printStackTrace();  }
        }
    };


    public void suonaTada(){
        Thread soundPlayingThread = new Thread(rumoreTada);
        soundPlayingThread.start();
    }

    public void suonaBop(){
        Thread soundPlayingThread = new Thread(rumoreBop);
        soundPlayingThread.start();
    }

    public void suonaLoser(){
        Thread soundPlayingThread = new Thread(rumoreLoser);
        soundPlayingThread.start();
    }
}